<?php

namespace App\Http\Controllers;

use App\Models\Report;
use Illuminate\Http\Request;

class ReportController extends Controller
{
    function list() {
        $pn = request()->input('pn', config('api.page_num'));
        $city = request()->input('city', '000000');
        $cityArray = ['000000'];
        $cityArray[] = $city;
        $cityArray[] = substr($city, 0, 4) . '00';
        $cityArray[] = substr($city, 0, 2) . '0000';
        $cityArray = array_unique($cityArray);

        $list = Report::where('status', 20)
            ->whereIn('city', $cityArray)
            ->orderby('id', 'desc')
            ->paginate($pn);
        return response()->json(['recode' => 1,
            'data' => ['last_page' => $list->lastPage()
                , 'page' => $list->currentPage()
                , 'list' => $list->items()]]);
    }

    public function info()
    {
        $id = request()->input('id', 0);

        $info = Report::find($id);

        $info->view += 1;
        $info->save();

        return response()->json([
            'recode' => 1,
            'info' => $info,
        ]);
    }
}
